var a = getApp();

Page({
    data: {
        baseUrl: a.globalData.baseUrl,
        urlBase: a.globalData.urlBase,
        imgsl: "",
        icon: "",
        name: "",
        remark: "",
        address: "",
        distance: "",
        lat: "",
        lng: "",
        store: [ {} ],
        imgsList: [ {
            imgs: ""
        } ],
        currentTab: "id1"
    },
    onLoad: function(t) {
        var e = this, r = a.globalData.urlBase + a.globalData.urlactivityList;
        e.getinitData(r), e.getDataqiang(), e.geikanData();
    },
    getinitData: function(t) {
        var e = this;
        wx.request({
            url: t,
            data: {
                lng: a.globalData.lng,
                lat: a.globalData.lat,
                page: e.data.page,
                limit: e.data.limit,
                storeId: a.globalData.storeId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var r = JSON.parse(t.data);
                0 != r.code && wx.showToast({
                    title: r.msg,
                    icon: "none",
                    duration: 2e3
                });
                var i = e.data.page;
                r.activityList.length < e.data.limit ? e.setData({
                    activityList: r.activityList,
                    hasMore: !1,
                    page: i + 1,
                    store: JSON.parse(t.data).store
                }) : e.setData({
                    activityList: r.activityList,
                    page: i + 1,
                    store: JSON.parse(t.data).store
                });
                var n = a.globalData.activityType;
                1 == n && e.setData({
                    currentTab: "id1"
                }), 2 == n && e.setData({
                    currentTab: "id2"
                }), 3 == n && e.setData({
                    currentTab: "id3"
                });
            }
        });
    },
    getDataqiang: function() {
        var t = this, e = a.globalData.baseUrl + a.globalData.urlQiang;
        wx.request({
            url: e,
            data: {
                lng: a.globalData.lng,
                lat: a.globalData.lat,
                storeId: a.globalData.storeId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var e = JSON.parse(a.data);
                0 != e.code ? wx.showToast({
                    title: "获取经纬度失败,请打开定位",
                    icon: "none",
                    duration: 2e3
                }) : t.setData({
                    quickList: e.quickList
                });
            }
        });
    },
    geikanData: function() {
        var t = this, e = a.globalData.baseUrl + a.globalData.urlkan;
        wx.request({
            url: e,
            data: {
                lng: a.globalData.lng,
                lat: a.globalData.lat,
                storeId: a.globalData.storeId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var e = JSON.parse(a.data);
                0 != e.code ? wx.showToast({
                    title: "获取经纬度失败,请打开定位",
                    icon: "none",
                    duration: 2e3
                }) : t.setData({
                    kanList: e.kanList
                });
            }
        });
    },
    swichNav: function(a) {
        var t = this;
        if (this.data.currentTab === a.target.dataset.current) return !1;
        t.setData({
            currentTab: a.target.dataset.current
        });
    },
    move: function(a) {},
    onReady: function(a) {},
    onShow: function() {
        var t = this, e = a.globalData.urlBase + a.globalData.urlactivityList;
        t.setData({
            activityList: [],
            page: 1,
            hasMore: !1
        }), t.getinitData(e), t.getDataqiang(), t.geikanData();
    },
    onHide: function() {},
    openMap: function() {
        var a = this;
        wx.openLocation({
            latitude: parseFloat(a.data.lat),
            longitude: parseFloat(a.data.lng),
            name: a.data.name,
            address: a.data.address
        });
    },
    onUnload: function() {},
    groupship: function(a) {
        wx.navigateTo({
            url: "../collageDetails/collageDetails?id=" + a.currentTarget.dataset.id + "&type=" + a.currentTarget.dataset.type
        });
    },
    groupPur: function(a) {
        wx.navigateTo({
            url: "purchaseDetail?id=" + a.currentTarget.dataset.id + "&type=" + a.currentTarget.dataset.type
        });
    },
    btnbargain: function(t) {
        var e = t.currentTarget.dataset.id, r = t.currentTarget.dataset.type, i = a.globalData.urlBase + a.globalData.urlAddActivityOrder;
        wx.request({
            url: i,
            data: {
                activityId: e,
                num: 1,
                userId: a.globalData.userId,
                type: r
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var e = JSON.parse(t.data);
                if (0 != e.code) wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 2e3
                }); else {
                    var r = e.msg;
                    wx.request({
                        url: a.globalData.baseUrl + a.globalData.urlBtnKan,
                        data: {
                            orderId: r,
                            userId: a.globalData.userId
                        },
                        method: "POST",
                        header: {
                            "content-type": "application/x-www-form-urlencoded"
                        },
                        success: function(a) {
                            var t = JSON.parse(a.data);
                            0 != t.code ? wx.showToast({
                                title: t.msg,
                                icon: "none",
                                duration: 2e3
                            }) : (wx.showToast({
                                title: "第一刀已砍" + t.msg,
                                icon: "none",
                                duration: 1e3
                            }), wx.navigateTo({
                                url: "bargainDetailsInvit?orderid=" + r
                            }));
                        }
                    });
                }
            }
        });
    },
    switchbuss: function() {
        wx.navigateTo({
            url: "../storeList/storeList?page=hd"
        });
    },
    onShareAppMessage: function() {}
});